package com.cloudm.technician.ui.widget

import android.view.View
import java.util.*

/**
 * 作者: wesley
 * 时间: 2017/11/22
 * 描述: 点击事件---避免重复点击
 */
abstract class OnceClickListener: View.OnClickListener {

    companion object {
        private const val MIN_CLICK_DELAY_TIME = 1000 //两次点击时间间隔
    }

    private var lastClickTime: Long = 0

    override fun onClick(view: View?) {
        view?.let {
            val currentTime = Calendar.getInstance().timeInMillis
            if (currentTime - lastClickTime > MIN_CLICK_DELAY_TIME) {
                lastClickTime = currentTime
                onOnceClick(it)
            }
        }
    }

    abstract fun onOnceClick(view: View)
}